Adding a min-cost flow library#29
Conversation
|
One high level comment before I go into the details of the API calls. There is a PR #18 by @sebulino that already changes the API of the Payment Session quite a bit and basically moves a lot over to the newly introduced pay class. While there are some differences I think it is also converging to the python example provided by @Lagrang3. I think the major difference is that in sebulinos's approach The The main reason that speaks against sebulinos approach of doing all in Looking forward for a good discussion and other / better arguments and thoughts than the ones that I have provided so far. |
|
@renepickhardt. At this point I have integrated my min-cost flow solver into Pickhardtpayments. How is it done?I am using a git submodule to pull my mincostflow repository from here. Thus for the moment I am keeping these two projects separate. I am anyways willing to put all my files here at some point to merge both projects. My mincostflow is written in C++, but I've just recently added a minimal working C-API and then a Python-API on top of that. So that you can call it from the python sources in Pickhardtpayments. We have discussed the possibility to write the Uncertainty Network in C++ as well, but for the moment we only have the Min-cost Flow solver in C++ and nothing beyond that. How to test this?Meson will take care to pull the submodule from github and compile my mincostflow library in two steps. we create a build directory At this point my mincostflow is built into And we can run the example Additional commentsMy project still depends on Ortools library for benchmarking, but that dependency is optional. It will compile even if it doesn't find it and you can still run benchmarks without ortools, it will just not run the ortools solver. Since Lagrang3/mincostflow appears as a git submodule, this project contains a link to a certain commit in that submodule. Therefore if something changes in Lagrang3/mincostflow, this project still will see the old commit, and in order to update it one needs to that will update the link to the latest commit in Lagrang3/mincosflow. The solver has been tested thoroughly, I have no doubts about its correctness. But once you run the example you will notice the runtime is too long. It takes about 10 to 15 seconds to perform a single min-cost flow in the lightning network. Next steps
|
this commit is makes sense only after this PR https://github.com/Lagrang3/mincostflow/pull/14 is merged.
|
I did a profile of the runtime of Pickhardpayments, running the and using my MCF library I get In this particular test case there where 4 iterations of the MCF. My solver had to initialize the graph only once and it did in 2.7 seconds. While the Ortools solver needed to build the graph data 4 times resulting in 3.1 seconds. |
|
The results for running |
|
At this point there are some observations:
Some ideas to solve the 1st issue: To tackle the 2nd issue: For the 3rd issue: |
|
@renepickhardt !!! Latest test: The pseudo-polynomial solver by successive shortest paths is faster than the Cost-scaling for the LN graph. This was one of the possibilities we foresaw at the beginning of the Summer of Bitcoin. The fact that different solvers could have different performance depending on the topology of the graph. |
|
Primal dual: |
|
I will paste here the entire output for the aforementioned run of |
|
Just adding a comment here as it's somewhat relevant: I have been working on an alternative min cost flow implementation as well for the Lightning Network. It's based on negative cycle cancellation on the derivative of the cost function (as opposed to linearisation of the problem), and it's already competitive with OrTools in every metric. Here's the implementation: https://github.com/adamritter/pickhardtpayments/ I also started integrating it to the Rust Lightning Development Kit (LDK), but it takes a lot more work to finish (and I would need help as well if anybody wants to help with productionizing MCF): |
Thanks @adamritter. Right now I am busy polishing the details on this little MCF project for Summer of Bitcoin. When I am done with that, I'd really like to collaborate on your solver. It is very exciting to see that you are already working to implement it into the Rust Lightning Development Kit! |
|
I am uploading here the latest benchmarks I obtained. The first plot shows the time spent in computing the MCF for three backends: Google's OR-tools (the underlying algorithm is cost-scaling) and two MCF solvers from my library using cost-scaling and augmenting-path (maybe better known as successive shortest path, sorry for the confusing naming). The lines indicate the mean value of the runtime and the shaded regions indicate the maximum and minimum runtime of the testcases. The second plot is the most important result of this PR. Our MCF solver, being tailored specifically for the Lightning Network, has the advantage that between iterations of Pickhardtpayments when the uncertainty network is updated the MCF data structure |
Sounds great, it will be awesome to improve lightning payments in real world. Right now I'm planning to port the simulator to use LDK payments / retries, as testing large payments in real life is really hard and scary (the possibility of losing thousands of dollars because of some software bug). |
|
Hi, this is just a question. Would it be hard to put in a feature in your fastest algorithm to make the fees part of the channel capacity? As I'm implementing the integration with LDK I have to take care of this just as much as min HTLC and base fees. I use satoshis and drop channels with bigger than 1 satoshi min HTLC and >0 base fees right now, but I wish I had implemented pct fees being part of the channel capacity as a part of the min cost algorithm, as it's not that hard to implement. What's important is to provide the pct fees for the edges of the graph and whenever a channel is updated, the capacity shouldn't be bigger than the routed flow / (1 - proportional forwarding fee). Another way to write it is that the incoming flow to the target node of an edge is equal to the outgoing flow * (1-proportional forwarding fee). |
|
Hi @adamritter. My first impression is that the Min. Cost Flow solver does just that. Any adjustment of costs and capacities should be performed in the following layer. |
|
I tried to solve this problem in a higher layer with hacks, but I couldn’t.
For example if we take probabilities out of the problem statement, let’s
suppose a path of 100, 100, 100, 100 capacities and 1% fee on each edge. A
standard min cost algorithm would think that it can route 100 units for 4%
fee, but in reality at most 100*0.99*0.99*0.99*0.99 units can arrive to the
target node.
Eduardo Quintana ***@***.***> (időpont: 2022. szept. 20., K,
11:07) ezt írta:
… Hi @adamritter <https://github.com/adamritter>. My first impression is
that the Min. Cost Flow solver does just that. Any adjustment of costs and
capacities should be performed in the following layer.
—
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN5SWAHDKKYANK635JVTZNDV7GEFRANCNFSM5ZM4Y6GQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Just to elaborate more, I solved the problem by increasing the target
amount by 1% and modifying the resulting paths with hacks, which is fine
for most cases in reality, but if it´s possible to move this problem inside
the min cost algorithm without sacrificing run-time, that means that less
hacks have to be around the algorithm.
Adam Ritter ***@***.***> (időpont: 2022. szept. 20., K, 11:20) ezt
írta:
… I tried to solve this problem in a higher layer with hacks, but I couldn’t.
For example if we take probabilities out of the problem statement, let’s
suppose a path of 100, 100, 100, 100 capacities and 1% fee on each edge. A
standard min cost algorithm would think that it can route 100 units for 4%
fee, but in reality at most 100*0.99*0.99*0.99*0.99 units can arrive to the
target node.
Eduardo Quintana ***@***.***> (időpont: 2022. szept. 20.,
K, 11:07) ezt írta:
> Hi @adamritter <https://github.com/adamritter>. My first impression is
> that the Min. Cost Flow solver does just that. Any adjustment of costs and
> capacities should be performed in the following layer.
>
> —
> Reply to this email directly, view it on GitHub
> <#29 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AN5SWAHDKKYANK635JVTZNDV7GEFRANCNFSM5ZM4Y6GQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
|
There should be then a correct algorithmic solution, which is not linear or convex MCF. It is a very interesting proposition, but we should, in my opinion, move this discussion to a dedicated thread/issue. |
|
Of course, no problem, I understand that it’s outside the problem space of
replacing Google’s min-cost flow algorithm. I just see that it’s harder for
me to work on improving the algorithm now that I moved to the integration
of the algorithm with the lightning network.
Eduardo Quintana ***@***.***> (időpont: 2022. szept. 20., K,
11:28) ezt írta:
… There should be then a correct algorithmic solution, which is not linear
or convex MCF. It is a very interesting proposition, but we should, in my
opinion, move this discussion to a dedicated thread/issue.
—
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN5SWAA4OF2HOZGBR6GYIR3V7GGVLANCNFSM5ZM4Y6GQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
@adamritter if you look at section 2.4 of our paper addressed the issue and noted that generalized min cost flow problems exist but that it seems not worthwhile during optimizsation to go for the exact fees as we approximate anyway |
|
Thanks, to tell you the truth, most of the problems I got were from trying
to pass the LDK routing unit tests, in whose test cases the fees can be
200% of the amount sent over the network. Most of the unit tests seemed to
test unrealistic cases though, so I ended up disabling the ones that were
too hard to pass.
Rene Pickhardt ***@***.***> (időpont: 2022. szept. 20., K,
11:44) ezt írta:
… @adamritter <https://github.com/adamritter> if you look at section 2.4 of
our paper <https://arxiv.org/abs/2107.05322> addressed the issue and
noted that generalized min cost flow problems exist but that it seems not
worthwhile during optimizsation to go for the exact fees as we approximate
anyway
—
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN5SWAH2NDXCE3ZHEVXYTQ3V7GIQPANCNFSM5ZM4Y6GQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|


Hi @renepickhardt.
I have prepared a draft for the C-API. I still owe you an example, I'll work on that.
I'm also proposing an example that illustrates the use of the Python-API from my point of view.
Very soon I will work on the specifics of the Python-API.
Just for the record: we have already a MCF solver in C++ in my repository https://github.com/Lagrang3/mincostflow
and we have a prototype of the uncertainty network and payment session already in this repository.
We are defining the C and Python APIs before implementation.
Comments are welcomed!